var path = require('path');
//引入插件-----------------

var HtmlwebpackPlugin = require('html-webpack-plugin');
var webpack = require('webpack');
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
let ExtractTextPlugin = require('extract-text-webpack-plugin');


//var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;  //压缩js代码
//定义了一些文件夹的路径
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'app');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');

module.exports = {
    //项目的文件夹 可以直接用文件夹名称 默认会找index.js 也可以确定是哪个文件名字，可以设置多个入口文件
    entry: ['babel-polyfill',APP_PATH],
    //输出的文件名 合并以后的js会命名为bundle.js
    output: {
        path: BUILD_PATH,
        filename: 'bundle.js' //'./js/[name].js' //文件输出形式 设置多个入口文件 就可以输出多个出口文件
    },
    //多个入口文件 多个出口文件
    //    entry: {
    //   bundle1: './main1.jsx',
    //   bundle2: './main2.jsx'
    // },
    // output: {
    //   filename: '[name].js'
    // },
    //添加我们的插件 会自动生成一个html文件
    plugins: [
        //使用插件-----------------------------
        new HtmlwebpackPlugin({
            title: 'Hello World app'
        }),
        commonsPlugin,
        new ExtractTextPlugin("[name].css")

        // , 压缩代码
        // new uglifyJsPlugin({
        //     compress: {
        //         warnings: false
        //     }
        // })
    ],
    // externals:{
    //     '$':'jQuery'
    // },
    devServer: {
        historyApiFallback: true,
        hot: true,
        inline: true,
        progress: true,
    },
    module: {
        loaders: [{
                test: /\.less$/,
                loader: "style-loader!css-loader!autoprefixer-loader?browsers=last 2 version!less-loader", //添加前缀
                include: APP_PATH
            }, {
                test: /\.css$/,
                loaders: ['style', 'css'],
                include: APP_PATH
            }, {
                test: /\.(png|jpg)$/,
                loader: 'url?limit=4000000000000'
            }
            , {
                test: /\.js$/,
                loader: 'babel',
                include: APP_PATH,
                query: {
                    presets: ['es2015']
                }
            }
            // , {
            //     test: /\.js$/,
            //     loader: ['babel'],
            //     include: APP_PATH,
            //     query: {
            //         "presets": ["stage-0"],//"es2015", 
            //         "plugins": [
            //             "transform-es3-property-literals",
            //             "transform-es3-member-expression-literals",
            //         ]
            //     }
            // }
        ]
    }
};
